package 剑指offer;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @description:
 * @author: ywk
 * @date: 2021-03-13
 */
public class 区间调度问题 {
    public static int intervalSchedule(int[][] arr) {
        if (arr.length == 0) {
            return 0;
        }
        Arrays.sort(arr, Comparator.comparingInt(o -> o[1]));
        int count = 1;
        int xEnd = arr[0][1];
        for (int i = 0; i < arr.length; i++) {
            int[] interval = arr[i];
            int start = interval[0];
            if (start >= xEnd) {
                count++;
                xEnd = interval[1];
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(intervalSchedule(new int[][]{{1, 3}, {2, 4}, {3, 6}}));
    }
}
